package com.bojx.report.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bojx.report.pojo.Result;
import com.bojx.report.pojo.StatisticResult;
import com.bojx.report.service.StatisticService;
import com.bojx.report.util.ResultUtil;
import com.bojx.report.validation.MonthStatisValidation;
import com.bojx.report.validation.QuarterStatisValidation;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.log.Log4jLog;
import com.jfinal.render.JsonRender;
/***
 * 统计
 * @author Administrator
 *
 */
public class StatisticsController extends Controller {
	private static final Log4jLog log=Log4jLog.getLog(StatisticsController.class);
	private static StatisticService statisticService=new StatisticService();
	public void month(){
		render("month.html");
	}
	
	public void quarter(){
		render("quarter.html");
	}
	
	@SuppressWarnings("rawtypes")
	@Before(MonthStatisValidation.class)
	public void monthData(){
		Result result = null;
		Integer year=getParaToInt("year");
		Integer month=getParaToInt("month");
		try {
			Map<String,Object> data=new HashMap<String,Object>();
			List<StatisticResult> count=statisticService.count(year, month);
			List<String> banks=statisticService.findBankUnupload(year,month);
			data.put("count", count);
			data.put("banks", banks);
			result = ResultUtil.success(data);
		} catch (Exception e2) {
			log.error(e2.getMessage(), e2);
			result = ResultUtil.error("10", e2.getMessage());
		}
		render(new JsonRender(result).forIE());
	}
	
	@SuppressWarnings("rawtypes")
	@Before(QuarterStatisValidation.class)
	public void quarterData(){
		Result result = null;
		Integer year=getParaToInt("year");
		Integer quarter=getParaToInt("quarter");
		try {
			Map<String,Object> data=new HashMap<String,Object>();
			List<StatisticResult> count=statisticService.countByQuarter(year, quarter);
			List<String> banks=statisticService.findBankUnuploadByQuarter(year,quarter);
			data.put("count", count);
			data.put("banks", banks);
			result = ResultUtil.success(data);
		} catch (Exception e2) {
			log.error(e2.getMessage(), e2);
			result = ResultUtil.error("10", e2.getMessage());
		}
		render(new JsonRender(result).forIE());
	}
}
